<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <el-form
        :model="where"
        label-width="96px"
        class="ele-form-search"
        @keyup.enter.native="reload"
        @submit.native.prevent>
        <el-col :lg="4" :md="4">
          <el-form-item label="订单状态">
            <el-select
              clearable
              v-model="where.status"
              placeholder="请选择"
              class="ele-fluid">
              <el-option label="等待打扫" value="0"/>
              <el-option label="已开始" value="2"/>
              <el-option label="超时未打扫" value="3"/>
            </el-select>

          </el-form-item>
        </el-col>
        <el-col :lg="6" :md="12">
          <div class="ele-form-actions">


            <el-button
              type="primary"
              icon="el-icon-search"
              class="ele-btn-icon"
              @click="reload">查询
            </el-button>
            <el-button @click="reset">重置</el-button>
            
<router-link to="/door/index"> <el-button >开大门</el-button></router-link>
          </div>
        </el-col>
      </el-form>
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :where="where"
        :datasource="url"
        :columns="columns"
        :selection.sync="selection"
        :page-sizes="[8, 10, 20, 100]"
        :page-size="8"
        height="calc(100vh - 315px)"

       >
        <!-- 表头工具栏 -->


        <!-- 1正常 0  冻结 -->

     <template slot="status" slot-scope="{row}">
          <el-tag v-if="row.status_name === '等待打扫'" type="danger" size="small">等待打扫</el-tag>
          <el-tag v-if="row.status_name === '已开始'" type="warning" size="small">已开始</el-tag>
          <el-tag v-if="row.status_name === '已完成'" type="success" size="small">已完成</el-tag>
          <el-tag v-if="row.status_name === '超时未打扫'" type="danger" size="small">超时未打扫</el-tag>
            <el-tag v-if="row.status_name === '大门门禁'" type="danger" size="small">大门门禁</el-tag>
        </template>
        <template slot="action" slot-scope="{row}">

          <div>

                <div style="float:left ">
                          <el-link
                            v-if="row.status !== 4"
                            type="primary"
                            slot="reference"
                            :underline="false" @click="Open(row)">
                            <el-button type="warning" size="mini">开门</el-button>
                          </el-link>
                        </div>
            <div style="width: 15px;">

            </div>

            <div :style="row.door_id ==1  ?'display: block':'display: none'" style="float: right: ;">
              <el-link
                v-if="row.status == 0 ||  row.status == 1"
                type="danger"
                :underline="false"
                @click="confirmDelivery(row)"
              >
                <el-button type="warning" size="mini">完成</el-button>
              </el-link>
            </div>


            <!-- 操作列 -->
          </div>
        </template>
      </ele-pro-table>
    </el-card>
    <!-- 编辑弹窗 -->

  </div>
</template>

<script>
import {mapGetters} from "vuex";


export default {
  name: 'ExamUsercrad',

  computed: {
    ...mapGetters(["permission"]),
  },
  data() {
    return {

      // 表格数据接口
      url: '/cleaning/index',
      // 表格列配置
      columns: [


        {
          prop: 'name',
          label: '包厢名称',
          showOverflowTooltip: true,
          minWidth: 130,
          align: 'center',
        },
    {
          prop: 'status_name',
          label: '状态',
          align: 'center',
          width: 100,
          resizable: false,
          slot: 'status',
        },
        {
          prop: 'add_time',
          label: '开始打扫时间',
          sortable: 'custom',
          showOverflowTooltip: true,
            resizable: false,
          minWidth: 200,
          align: 'center',
          formatter: (row, column, cellValue) => {
            return this.$util.toDateString(cellValue);
          }
        },
        // {
        //   prop: 'end_time',
        //   label: '到期时间',
        //   ortable: 'custom',
        //   showOverflowTooltip: true,
        //     resizable: false,
        //   minWidth: 200,
        //   align: 'center',
        //   formatter: (row, column, cellValue) => {
        //     return this.$util.toDateString(cellValue);
        //   }
        // },






        {
          columnKey: 'action',
          label: '操作',
          width: 140,
          align: 'center',
          resizable: false,
          slot: 'action',
         //   fixed: "right"

        },
        {
          prop: 'order_on',
          label: '订单号',
          align: 'center',
          width: 250,
          resizable: false,

        },

      ],
      // 表格搜索条件
      where: {},
      // 表格选中数据
      selection: [],
      typeList: [],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false,
      showEdits: false,
    };
  },

  methods: {
    /* 刷新表格 */
    reload() {
      this.$refs.table.reload({where: this.where});
    },
    /* 重置搜索 */
    reset() {
      this.where = {};
      this.reload();
    },
    /* 显示编辑 */
    openEdit(row) {

      this.current = row;
      this.showEdit = true;
    },

    /* 显示编辑 */
    openEdits(row) {

      this.current = row;
      this.showEdits = true;
    },
    /* 删除 */
    remove(row) {
      const loading = this.$loading({lock: true});
      this.$http.post('/order/delete', {id: row.order_id}).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          this.reload();
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },
    endorder(row) {
      const loading = this.$loading({lock: true});
      this.$http.post('/order/endorder', {id: row.order_id}).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          this.reload();
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },
    /* 确认同城配送已配送 */
    confirmDelivery(row) {
      const loading = this.$loading({lock: true});
      this.$http.post('/cleaning/confirmDelivery', {id: row.id}).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          this.reload();
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },
    /* 批量删除 */
    removeBatch() {
      if (!this.selection.length) {
        this.$message.error('请至少选择一条数据');
        return;
      }
      this.$confirm('确定要删除选中的用户期限卡吗?', '提示', {
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({lock: true});
        this.$http.post('/cradorder/delete', {id: this.selection.map(d => d.id)}).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      }).catch(() => {
      });
    },


    /* 更改1正常 0  冻结 3 */
    status(row) {
      const loading = this.$loading({lock: true});
      let params = Object.assign({
        "id": row.id,
        "status": row.status
      })
      this.$http.post('/cradorder/status', params).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
        } else {
          row.status = !row.status ? 1 : 2;
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },
    Open(row) {
      const loading = this.$loading({lock: true});
      this.$http.post('/cleaning/open', {id: row.id}).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          this.reload();
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },
  }
}
</script>

<style>
/* .el-table{
  font-size: 20px;
} */
</style>
